home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / games / sprocketinvaders / source / gameobject.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  3.5 KB  |  111 lines

  1. //•    ------------------------------------------------------------------------------------------    •
  2. //•
  3. //•    Copyright © 1996 Apple Computer, Inc., All Rights Reserved
  4. //•
  5. //•
  6. //•        You may incorporate this sample code into your applications without
  7. //•        restriction, though the sample code has been provided "AS IS" and the
  8. //•        responsibility for its operation is 100% yours.  However, what you are
  9. //•        not permitted to do is to redistribute the source as "DSC Sample Code"
  10. //•        after having made changes. If you're going to re-distribute the source,
  11. //•        we require that you make it clear in the source that the code was
  12. //•        descended from Apple Sample Code, but that you've made changes.
  13. //•
  14. //•        Authors:
  15. //•            Chris De Salvo
  16. //•
  17. //•    ------------------------------------------------------------------------------------------    •
  18.  
  19. #ifndef __GAMEOBJECT__
  20. #define __GAMEOBJECT__
  21.  
  22. //•    ------------------------------    Includes
  23.  
  24. #include "Particles.h"
  25. #include "Sprite.h"
  26.  
  27. //•    ------------------------------    Public Definitions
  28.  
  29. typedef enum ObjectKind
  30. {
  31.     objectEnemy,
  32.     objectEnemyShot,
  33.     objectGreenPlayer,
  34.     objectGreenPlayerShot,
  35.     objectRedPlayer,
  36.     objectRedPlayerShot,
  37.     objectEnemyParticles,
  38.     objectPlayerParticles,
  39.     objectPlasmaParticles,
  40.     objectMissileParticles
  41. } ObjectKind;
  42.  
  43. //•    ------------------------------    Public Types
  44.  
  45. //•    Forward declaration of this structure so we can build a link list of
  46. //•    them within the actual structure
  47. struct GameObject;
  48. typedef struct GameObject GameObject, *GameObjectPtr, **GameObjectHandle;
  49.  
  50. typedef void (*ObjectAction)(GameObjectPtr theObject);
  51.  
  52. struct GameObject
  53. {
  54.     GameObjectPtr    next;
  55.     GameObjectPtr    prev;
  56.  
  57.     ObjectKind        kind;
  58.  
  59.     Rect            screenRect;        //•    The area of the screen that the object was last drawn in
  60.     Rect            oldScreenRect;    //•    Last rect where the sprite was drawn
  61.     SInt16            screenX;        //•    Where the hotspots are in screen space
  62.     SInt16            screenY;
  63.     
  64.     SInt16            velocityH;
  65.     SInt16            velocityV;
  66.     
  67.     Rect            bounds;            //•    The object must stay within this rectangle.  This is defined in screen space
  68.     
  69.     SInt16            frame;            //•    Which frame of animation is being displayed
  70.     UInt32            time;            //•    Local time for this object
  71.     
  72.     union
  73.     {
  74.         SpritePtr    sprite;            //•    Animation frames and hot-spots for this object
  75.         ParticlesPtr particles;        //•    Particle system for particle objects
  76.     } objectData;
  77.  
  78.     ObjectAction    action;            //•    This function controls all object actions
  79.     UInt32            refCon;            //•    Client-defined 32-bit scratch variable
  80. };
  81.  
  82. //•    ------------------------------    Public Variables
  83.  
  84. extern unsigned long    gNumGameObjects;
  85.  
  86. //•    ------------------------------    Public Functions
  87.  
  88. #ifdef __cplusplus
  89. extern "C" {
  90. #endif
  91.  
  92. extern GameObjectPtr GameObjectAllocate(void);
  93. extern void GameObjectDispose(GameObjectPtr go);
  94. extern void GameObjectAddToList(GameObjectPtr *list, GameObjectPtr go);
  95. extern void GameObjectRemoveFromList(GameObjectPtr *list, GameObjectPtr go);
  96. extern void GameObjectDisposeList(GameObjectPtr *list);
  97. extern void GameObjectSetSprite(GameObjectPtr go, SpritePtr sprite);
  98. extern SpritePtr GameObjectGetSprite(GameObjectPtr go);
  99. extern void GameObjectSetParticles(GameObjectPtr go, ParticlesPtr particles);
  100. extern ParticlesPtr GameObjectGetParticles(GameObjectPtr go);
  101. extern void GameObjectSetBounds(GameObjectPtr go, RectPtr r);
  102. extern RectPtr GameObjectGetBounds(GameObjectPtr go);
  103. extern void GameObjectListAdvance(GameObjectPtr list);
  104. extern void GameObjectListDraw(GameObjectPtr list, CGrafPtr dest);
  105. extern UInt32 GameObjectListCount(GameObjectPtr list);
  106.  
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110.  
  111. #endif